package com.tutu.mp.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Program: SpringBoot
 * @Description: mp字段填充配置类
 * @Author: JK.TuTu
 * @ @Version: 1.0
 * @Create: 2022-11-29 11:30
 **/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 插入操作会自动填充
     *
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("deleted", 0);
    }


    /**
     * 更新时会自动填充
     *
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
    }
}
